<div class="sm-rightPanel">
        <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-card-header">标题</div>
        <div class="layui-card-body">
         		 内容
         		   <div class="layui-form-item">
					    <label class="layui-form-label">联动选择框</label>
					    <div class="layui-input-inline">
					      <select name="quiz1">
					        <option value="">请选择省</option>
					        <option value="浙江" selected="">浙江省</option>
					        <option value="你的工号">江西省</option>
					        <option value="你最喜欢的老师">福建省</option>
					      </select>
					    </div>
					    <div class="layui-input-inline">
					      <select name="quiz2">
					        <option value="">请选择市</option>
					        <option value="杭州">杭州</option>
					        <option value="宁波" disabled="">宁波</option>
					        <option value="温州">温州</option>
					        <option value="温州">台州</option>
					        <option value="温州">绍兴</option>
					      </select>
					    </div>
					    <div class="layui-input-inline">
					      <select name="quiz3">
					        <option value="">请选择县/区</option>
					        <option value="西湖区">西湖区</option>
					        <option value="余杭区">余杭区</option>
					        <option value="拱墅区">临安市</option>
					      </select>
					    </div>
					    <div class="layui-form-mid layui-word-aux">此处只是演示联动排版，并未做联动交互</div>
					  </div> 
        </div>
      </div>
    </div>
</div>

<script>
    layui.use(['layui','layer', 'select'], function () {
        var layer = layui.layer;
        var table = layui.table;


        var tableObj = table.render({
            id: 'list_table',
            elem: '#list_table',
            url: '..',
            align: "center",
            cols: [[ //表头
                {type: 'checkbox'},
                {type: 'numbers', title: '序号',width:50},
                {field: 'inputcode', title: '关键词', width: 150, align: 'center',},
                {field: 'title', title: '标题', width: 150, align: 'center',},
                {field: 'content', title: '消息描述', align: 'center',},
                {
                    field: 'lock', title: '操作', width: 150, align: 'center', templet: function (d) {
                    return '<a class="font-primary2" lay-event="edit" href="javascript:;">修改</a>' +
                        '<a class="font-primary" lay-event="mass" href="javascript:;">群发</a>';
                }, unresize: true, align: 'center'
                }
            ]],
        });

        $("#search").click(function () {
            smartAui.reloadTable(tableObj);
        });

        // 添加
        $("#msg_add").click(function () {
            smartAui.dialog({
                title: '添加'
                , template: 'add'
                , saveUrl: '/msgtext/updateText'
                , tableObj: tableObj
            })
        });

        // 删除
        $("#msg_del").click(function () {
            var data = table.checkStatus('list_table').data;//已选中数据
            if (data.length == 0) {
                layer.msg("至少选择一条");
                return;
            }
            var arr = [];     //选中数组
            for (var i = 0; i < data.length; i++) {
                arr.push(data[i].baseId)
            }
            smartAui.confirm("确认删除？", function () {
                $.ajax({
                    url: '/msgtext/deleteById',
                    data: {"baseId": arr.join(",")},
                    success: function (result) {
                        if (result.success) {
                            layer.msg("删除成功");
                            smartAui.reloadTable(tableObj);
                        } else {
                            layer.msg("删除失败");
                        }
                    }
                })
            });
        });


        //表格内部操作按钮监听
        table.on('tool(mainList)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
		
            if (layEvent === 'edit') {
                smartAui.dialog({
                    title: '修改',
                    template: 'edit',
                    saveUrl: '/msgtext/updateText',
                    tableObj: tableObj,
                    htmlData: data,
                })
            } else if (layEvent === 'mass') {
                smartAui.dialog({
                    title: '群发',
                    template: '/views/common/template/fans-chose.html',
                    height: 600,
                    yes:function (index) {
                        if(GLOBAL.choosed.length<2){
                            layer.msg("至少选择2个粉丝");
                            return false;
                        }
                        $.ajax({
                            url: '/wxapi/massSendTextByOpenIds',
                            data: {
                            	textId:data.id,
                                openIds: GLOBAL.choosed.join(",")
                            },
                            success: function (result) {
                                if ( result == "1") {
                                    layer.msg("群发成功");
                                    smartAui.reloadTable(tableObj);
                                    layer.close(index);
                                } else {
                                    layer.msg("群发失败");
                                }
                            }
                        })
                    },
                    end:function () {
                        GLOBAL.choosed=[];
                    }
                });
            }
        });



    });
</script>
